// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License.
// See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
// All other rights reserved.
using System;
using System.Collections.Generic;
using System.Web.Services;
using DAO;
using DTO;
using BUS;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class AutoComplete : WebService
{
    public AutoComplete()
    {
    }

    [WebMethod]
    public List<string> GetCompletionList(string prefixText, int count)
    {
        if (count == 0)
        {
            count = 10;
        }

        List<ThanhVienDTO> thanhvien = new List<ThanhVienDTO>();
        List<string> danhsach = new List<string>();
        try
        {
            thanhvien = ThanhVienBUS.LayDanhSachThanhVienTheoUsername(prefixText);
            foreach (ThanhVienDTO thanhviendto in thanhvien)
            {

                if (thanhviendto.MaNhomThanhVien != 2)
                    danhsach.Add(thanhviendto.Username);
                else
                    danhsach.Add(prefixText);
            }
            return danhsach;
        }
        catch (Exception)
        {
            return danhsach;
        }        
    }
}